﻿<?php
session_start();
include_once  "config.php";
?>

<html>
<head>
<title>查看购物车</title>
<link href="style/style.css" rel="stylesheet" type="text/css"></head>
<body>
<h1 align="center">查看购物车</h1>
<div class="cart-view-table-back">
<form method="post" action="cart_update.php">
<table width="100%"  cellpadding="6" cellspacing="0"><thead><tr><th>数量</th><th>商品名</th><th>价格</th><th>合计</th><th>退订</th></tr></thead>
  <tbody>
 	<?php
	if(isset($_SESSION["cart_products"])) //存在商品
    {
		$total = 0; //全部商品总付款额
		$b = 0; //背景色标志 
		foreach ($_SESSION["cart_products"] as $cart_itm)
        {
			//从会话变量取数
			$product_name = $cart_itm["product_name"];
			$product_qty = $cart_itm["product_qty"];
			$product_price = $cart_itm["product_price"];
			$product_code = $cart_itm["product_code"];
			$product_color = $cart_itm["product_color"];
			$subtotal = ($product_price * $product_qty); //每件商品的合计金额
			
		   	$bg_color = ($b++%2==1) ? 'odd' : 'even'; //class for zebra stripe 
		    echo '<tr class="'.$bg_color.'">';
			echo '<td><input type="text" size="2" maxlength="2" name="product_qty['.$product_code.']" value="'.$product_qty.'" /></td>';
			echo '<td>'.$product_name.'</td>';
			echo '<td>'.$product_price.'</td>';//
			echo '<td>'.$subtotal.'</td>';//
			echo '<td><input type="checkbox" name="remove_code[]" value="'.$product_code.'" /></td>';
            echo '</tr>';
			$total = ($total + $subtotal); //全部商品总付款额
        }
		
		$grand_total = $total + $shipping_cost; //实际支付额（商品金额+运费）

		$shipping_cost = ($shipping_cost)?'运费 : '.sprintf("%01.2f", $shipping_cost).'<br />':'';
	}
    ?>
    <tr><td colspan="5"><span style="float:right;text-align: right;"><?php echo $shipping_cost; ?>付款总额: <?php echo sprintf("%01.2f", $grand_total);?></span></td></tr>
    <tr><td colspan="5"><a href="index.php" class="button">继续选购</a><button type="submit">刷新</button></td></tr>
  </tbody>
</table>
<input type="hidden" name="return_url" value="<?php 
$current_url = urlencode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
echo $current_url; ?>" />
</form>
</div>

</body>
</html>
